package com.easy.api.http;

import com.easy.api.factory.api.request.GetApiMapping;
import com.easy.api.factory.api.request.PostApiMapping;

/**
 * @Author liuyuan
 * @Date 2020-04-24 09:30
 * @Version 1.0
 */
public enum HttpMethod {
    GET("get","getApiMapping", GetApiMapping.class),
    HEAD("head","headApiMapping", PostApiMapping.class),
    POST("post","postApiMapping",null),
    PUT("put","putApiMapping",null),
    PATCH("patch","patchApiMapping",null),
    DELETE("delete","deleteApiMapping",null),
    OPTIONS("options","optionsApiMapping",null),
    TRACE("trace","traceApiMapping",null);

    private String code;

    private String service;

    private Class<?> aClass;

    public static HttpMethod toEnum(String code) {
        for (HttpMethod category : HttpMethod.values()) {
            if (category.getCode().equals(code)) {
                return category;
            }
        }
        return null;
    }

    HttpMethod(String code, String service,Class<?> aClass) {
        this.code = code;
        this.service = service;
        this.aClass = aClass;
    }

    public Class<?> getaClass() {
        return aClass;
    }

    public void setaClass(Class<?> aClass) {
        this.aClass = aClass;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getService() {
        return service;
    }

    public void setService(String service) {
        this.service = service;
    }

    public static void main(String[] args) {
        HttpMethod httpMethod = HttpMethod.toEnum(HttpMethod.GET.code);
        String service = httpMethod.getService();
        System.out.println(service);
    }
}
